{{/* Copyright 2017 The LUCI Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */}}

{{define "title"}}Builder {{.Model.Builder.ID.Builder}}{{end}}

{{define "head"}}
<style type="text/css">
  form {
    margin: 1.5em 0;
  }
  .status .outdated {
    color: red;
    font-size: x-large;
  }
</style>
{{end}}

{{define "content"}}
  {{with $b := .Model}}
<ol class="breadcrumb">
  <li class="active">
    <a href="/">All masters</a>
  </li>
  <li class="active">
    <a href="/masters/{{$b.Builder.ID.Master}}/">{{$b.Builder.ID.Master}}</a>
  </li>
  <li class="active">
    <a href="/masters/{{$b.Builder.ID.Master}}/builders/{{$b.Builder.ID.Builder}}/">{{$b.Builder.ID.Builder}}</a>
  </li>
</ol>

<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <h2>Builder {{$b.Builder.ID.Builder}}</h2>

      <p>
        <a href="https://chromium.googlesource.com/infra/infra/+/master/go/src/infra/appengine/luci-migration/README.md">
          How to use it?</a>
      </p>

      <div>
        Buildbot:
        <a href="https://ci.chromium.org/buildbot/{{$b.Builder.ID.Master}}/{{$b.Builder.ID.Builder}}/">builds</a>,
        <a href="https://goto.google.com/buildbucket-dashboard?duration=1w&bucket=master.{{$b.Builder.ID.Master}}&amp;builder={{$b.Builder.ID.Builder}}">metrics</a>.
      </div>

      <div>
        LUCI:
        <a href="https://ci.chromium.org/buildbucket/{{$b.LUCIBucket}}/{{$b.Builder.ID.Builder}}/">builds</a>,
        <a href="https://goto.google.com/buildbucket-dashboard?duration=1w&bucket={{$b.LUCIBucket}}&amp;builder={{$b.Builder.ID.Builder}}">metrics</a>.
      </div>

      <div>
        Tracking bug:
        <a href="{{$b.Builder.IssueID.URL}}">{{$b.Builder.IssueID.URL}}</a>
      </div>

      <form method="post" class="form-inline">
        <input type="hidden" id="xsrf_token" name="xsrf_token" value="{{$.XsrfToken}}">
        <input type="hidden" id="action" name="action" value="update">
        {{if $b.TryBuilder}}
        <div class="form-group">
          <label for="experimentLevel">Experiment percentage</label>
          <input id="experimentLevel" name="experimentLevel" type="range" list="tickmarks" value="{{$b.ExperimentLevel}}"
            max="10">
          <datalist id="tickmarks">
            <option value="0">
            <option value="1">
            <option value="2">
            <option value="3">
            <option value="4">
            <option value="5">
            <option value="6">
            <option value="7">
            <option value="8">
            <option value="9">
            <option value="10">
          </datalist>
        </div>
        {{end}}
        <label>
            <input id="luciIsProd" name="luciIsProd" type="checkbox" {{if $b.Builder.LUCIIsProd}}checked{{end}}> LUCI Is Prod?
        </label>
        <div>
          <input name="reason" placeholder="reason, required">
          <button type="submit" class="btn btn-default">Update</button>
          <a href="changes">Change log</a>
        </div>
      </form>

    {{if $b.TryBuilder}}
      <form method="post" class="form-inline">
          <input type="hidden" id="xsrf_token" name="xsrf_token" value="{{$.XsrfToken}}">
          <input type="hidden" id="action" name="action" value="analyze">
        <button type="submit" class="btn btn-default">Start analysis now</button>
        it may take a minute or two
      </form>
      {{if not $b.StatusKnown}}
      <div class="alert alert-info" role="alert" style="margin-top: 10px">
        Migration status is unknown.
        Perhaps this builder was not analyzed yet.
      </div>
      {{else}}
      <h2>Latest comparison</h2>
      <div class="status">
        Status: <span class="label label-{{$b.StatusClassSuffix}}">{{$b.Builder.Migration.Status}}</span>
        as of
        <span class="{{if $b.StatusOutdated}}outdated{{end}}">
          {{$b.StatusAge | durationString}} ago
        </span>
      </div>
      <div>
        LUCI Correctness:
        {{$b.Builder.Migration.Correctness | percent}}%
      </div>
      <div>
        LUCI Speed: {{$b.Builder.Migration.Speed | percent}}%
      </div>
      <div>
        LUCI Health: {{$b.Builder.Migration.InfraHealth | percent}}%
      </div>

      <h3>Why?</h3>
      <div>{{$b.Details}}</div>
      {{end}}
    {{else}}
      <div class="status">
        Status: <span class="label label-{{$b.StatusClassSuffix}}">{{$b.Builder.Migration.Status}}</span>
      </div>
    {{end}}
    </div>
  </div>
</div>
  {{end}}
{{end}}
